package com.clarence.dada.modular.system.config.api;

import com.clarence.dada.core.redis.RedisOperatorApi;
import com.clarence.dada.core.redis.start.SecurityRedisCacheAutoConfiguration;
import com.clarence.dada.modular.system.user.service.DragCaptchaService;
import com.clarence.dada.modular.system.user.service.impl.DragCaptchaServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 图形验证码自动配置
 *
 * @author fengshuonan
 * @since 2020/12/1 21:44
 */
@Configuration
@AutoConfigureAfter(SecurityRedisCacheAutoConfiguration.class)
public class CaptchaAutoConfiguration {

    @Resource(name = "captchaCache")
    private RedisOperatorApi<String> captchaCache;

    /**
     * 拖拽验证码工具
     *
     * @author fengshuonan
     * @since 2021/7/5 11:57
     */
    @Bean
    @ConditionalOnMissingBean(DragCaptchaService.class)
    public DragCaptchaService dragCaptchaService() {
        // 验证码过期时间 120秒
        return new DragCaptchaServiceImpl(captchaCache);
    }

}
